package com.alipay.pluginmodule

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.alipay.pluginframework.HookManager


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        findViewById<Button>(R.id.buttonOne).setOnClickListener {
            loadPlugin()
        }

        findViewById<Button>(R.id.buttonTwo).setOnClickListener {
            startProxy()
        }
        val stringExtra = intent.getStringExtra("data")?:""
        Log.e("-----",stringExtra)

    }

    private fun startProxy() {
        //这里就是一个占坑的activity
        val intent = Intent(this, ProxyActivity::class.java)
        //这里是拿到我们加载的插件的第一个activity的全类名
        intent.putExtra("ClassName", "com.alipay.pluginapp.MainActivity")//HookManager.getInstance().packageInfo.activities[0].name
        intent.putExtra("data","这是主App来的数据")
        startActivity(intent)
    }

    /**
     * 加载插件
     */
    private fun loadPlugin() {
        HookManager.getInstance().loadPlugin(applicationContext);
        Toast.makeText(this, "加载完成", Toast.LENGTH_LONG).show();
    }
}